<title>支付订单</title>
<div class="layui-card layadmin-header">
  <div class="layui-breadcrumb" lay-filter="breadcrumb">
    <a lay-href="">主页</a>
    <a><cite>订单管理</cite></a>
  </div>
</div>

    <!--<div class="layui-fluid">-->
      <!--<div class="layui-card">-->
        <!--<div class="layui-tab layui-tab-brief">-->
          <!--<ul class="layui-tab-title">-->
            <!--<li class="layui-this">支付订单</li>-->
          <!--</ul>-->
          <!--<div class="layui-tab-content">-->
            <!--<div class="layui-tab-item layui-show">-->
              <!--<div class="layui-row">-->
                <!--<div class="layui-form" style="float:right; margin-bottom: 10px;">-->
                  <!--<div class="layui-form-item" style="margin:0;">-->
                    <!--<div class="layui-input-inline">-->
                      <!--<input type="text" name="createTimeStart" id="createTimeStart" autocomplete="off" placeholder="开始时间" class="layui-input">-->
                    <!--</div>-->
                    <!--<div class="layui-input-inline">-->
                      <!--<input type="text" name="createTimeEnd" id="createTimeEnd" autocomplete="off" placeholder="结束时间" class="layui-input">-->
                    <!--</div>-->
                    <!--<div class="layui-input-inline">-->
                      <!--<input type="text" name="mchId" id="mchId" placeholder="商户ID" autocomplete="off" class="layui-input">-->
                    <!--</div>-->
                    <!--<div class="layui-input-inline">-->
                      <!--<input type="text" name="payOrderId" id="payOrderId" placeholder="支付订单号" autocomplete="off" class="layui-input">-->
                    <!--</div>-->
                    <!--<div class="layui-input-inline">-->
                      <!--<input type="text" name="mchOrderNo" id="mchOrderNo" placeholder="商户订单号" autocomplete="off" class="layui-input">-->
                    <!--</div>-->
                    <!--<div class="layui-input-inline">-->
                      <!--<select name="productId" id="productId" lay-search="">-->
                        <!--<option value="-99">支付产品</option>-->
                      <!--</select>-->
                    <!--</div>-->
                    <!--<div class="layui-input-inline">-->
                      <!--<select name="type" id="productType" placeholder="产品类型" lay-search="">-->
                        <!--<option value="-99">产品类型</option>-->
                        <!--<option value="1">收款</option>-->
                        <!--<option value="2">充值</option>-->
                      <!--</select>-->
                    <!--</div>-->
                    <!--<div class="layui-input-inline">-->
                      <!--<select name="status" id="status" lay-search="">-->
                        <!--<option value="-99">订单状态</option>-->
                        <!--<option value="0">订单生成</option>-->
                        <!--<option value="1">支付中</option>-->
                        <!--<option value="2">支付成功</option>-->
                        <!--<option value="-1">支付失败</option>-->
                        <!--<option value="3">处理完成</option>-->
                        <!--<option value="4">已退款</option>-->
                      <!--</select>-->
                    <!--</div>-->
                    <!--&lt;!&ndash;<button id="search" class="layui-btn" data-type="reload">搜索</button>&ndash;&gt;-->
                    <!--<button id="search" class="layui-btn layuiadmin-btn-admin" data-type="reload"><i class="layui-icon layui-icon-search"></i>搜索</button>-->

                  <!--</div>-->
                <!--</div>-->
                <!--<div class="layui-form-item">-->
                  <!--<blockquote class="layui-elem-quote" id="orderPayAmountTip">-->

                    <!--提交订单数:<sapn id="orderPayAmountTip_allTotalCount" style="background-color: #23c6c8;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></sapn>-->
                    <!--已付订单数:<span id="orderPayAmountTip_successTotalCount" style=" background-color: #23c6c8;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>-->
                    <!--未付订单数:<span id="orderPayAmountTip_failTotalCount" style=" background-color: #FD482C;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>-->
                  <!--</blockquote>-->
                <!--</div>-->
                <!--<div class="layui-form-item">-->
                  <!--<blockquote class="layui-elem-quote" id="orderPayAmountTip2">-->
                    <!--订单总金额:<span id="orderPayAmountTip_allTotalAmount" style="background-color: #23c6c8;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>-->
                    <!--已付总金额:<span id="orderPayAmountTip_successTotalAmount" style="background-color: #23c6c8;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>-->
                    <!--未付总金额:<span id="orderPayAmountTip_failTotalAmount" style=" background-color: #FD482C;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>-->

                  <!--</blockquote>-->
                <!--</div>-->
                <!--<div class="layui-form-item">-->
                  <!--<blockquote class="layui-elem-quote" id="orderPayAmountTip3">-->
                    <!--商户总收入:<span id="orderPayAmountTip_successTotalMchIncome" style="background-color: #23c6c8;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>-->
                    <!--代理商收入:<span id="orderPayAmountTip_successTotalAgentProfit" style="background-color: #23c6c8;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>-->
                    <!--平台收入:<span id="orderPayAmountTip_successTotalPlatProfit" style="background-color: #23c6c8;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>-->
                  <!--</blockquote>-->
                <!--</div>-->
              <!--</div>-->
              <!--<table id="XxPay_Mgr_PayOrder_dataAll" lay-filter="XxPay_Mgr_PayOrder_dataAll"></table>-->
            <!--</div>-->

          <!--</div>-->
        <!--</div>-->
      <!--</div>-->
    <!--</div>-->

<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-tab-content">
      <div class="layui-btn-group demoTable lay-mb15">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-useradmin-formlist">
          <div class="layui-form-item" style="margin:0;">
            <div class="layui-form-item" style="margin:0;">
              <div class="layui-inline">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-block">
                  <input type="text" name="createTimeStart" id="createTimeStart" autocomplete="off" placeholder="开始时间" class="layui-input">
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-block">
                  <input type="text" name="createTimeEnd" id="createTimeEnd" autocomplete="off" placeholder="结束时间" class="layui-input">
                </div>
              </div>

              <div class="layui-inline">
                <label class="layui-form-label">商户ID</label>
                <div class="layui-input-block">
                  <input type="text" name="mchId" id="mchId" placeholder="商户ID" autocomplete="off" class="layui-input">
                </div>
              </div>

              <div class="layui-inline">
                <label class="layui-form-label">支付订单号</label>
                <div class="layui-input-block">
                  <input type="text" name="payOrderId" id="payOrderId" placeholder="支付订单号" autocomplete="off" class="layui-input">
                </div>
              </div>


              <div class="layui-inline">
                <label class="layui-form-label">支付产品</label>
                <div class="layui-input-block">
                  <select name="productId" id="productId" lay-search="">
                     <option value="-99">支付产品</option>
                  </select>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">产品类型</label>
                <div class="layui-input-block">
                  <select name="type" id="productType" placeholder="产品类型" lay-search="">
                    <option value="-99">产品类型</option>
                    <option value="1">收款</option>
                    <option value="2">充值</option>
                  </select>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">订单状态</label>
                <div class="layui-input-block">
                  <select name="status" id="status" lay-search="">
                    <option value="-99">订单状态</option>
                    <option value="0">订单生成</option>
                    <option value="1">支付中</option>
                    <option value="2">支付成功</option>
                    <option value="-1">支付失败</option>
                    <option value="3">处理完成</option>
                    <option value="4">已退款</option>
                  </select>
                </div>
              </div>
              <div class="layui-inline">
                <label class="layui-form-label">商户订单号</label>
                <div class="layui-input-block">
                  <input type="text" name="mchOrderNo" id="mchOrderNo" placeholder="商户订单号" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-inline">
                <button id="search" class="layui-btn layuiadmin-btn-admin" data-type="reload">
                  <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
              </div>

            </div>
          </div>
        </div>
      </div>
      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
          <!--<a class="layui-btn layui-btn-normal" data-type="add" lay-href="merchant/list/mch_add"><i class="layui-icon"></i>添加商户</a>-->
          <!--<a class="layui-btn layui-btn-warm" data-type="export" lay-href="merchant/list/mch_add"><i class="layui-icon layui-icon-download-circle"></i>导出数据</a>-->

          <!--<button id="addChannelMch" class="layui-btn layui-btn-normal" data-type="add"><i class="layui-icon"></i>添加-->
          <!--</button>-->
          <!--<button id= "output" class="layui-btn layui-btn-warm" data-type="output"><i class="layui-icon layui-icon-download-circle"></i>导出-->
          <!--</button>-->
          <!--<button id= "batchdel" class="layui-btn layui-btn-danger" data-type="batchdel"><i class="layui-icon"></i>删除-->
          <!--</button>-->

        </div>
        <div class="layui-form-item">
          <blockquote class="layui-elem-quote" id="orderPayAmountTip">

            提交订单数:<sapn id="orderPayAmountTip_allTotalCount" style="background-color: #23c6c8;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></sapn>
            已付订单数:<span id="orderPayAmountTip_successTotalCount" style=" background-color: #23c6c8;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>
            未付订单数:<span id="orderPayAmountTip_failTotalCount" style=" background-color: #FD482C;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>
          </blockquote>
        </div>
        <div class="layui-form-item">
          <blockquote class="layui-elem-quote" id="orderPayAmountTip2">
            订单总金额:<span id="orderPayAmountTip_allTotalAmount" style="background-color: #23c6c8;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>
            已付总金额:<span id="orderPayAmountTip_successTotalAmount" style="background-color: #23c6c8;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>
            未付总金额:<span id="orderPayAmountTip_failTotalAmount" style=" background-color: #FD482C;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>

          </blockquote>
        </div>
        <div class="layui-form-item">
          <blockquote class="layui-elem-quote" id="orderPayAmountTip3">
            商户总收入:<span id="orderPayAmountTip_successTotalMchIncome" style="background-color: #23c6c8;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>
            代理商收入:<span id="orderPayAmountTip_successTotalAgentProfit" style="background-color: #23c6c8;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>
            平台收入:<span id="orderPayAmountTip_successTotalPlatProfit" style="background-color: #23c6c8;color: #FFFFFF;font-size: 10px;font-weight: 600;padding: 3px 8px;text-shadow: none;"></span>
          </blockquote>
        </div>

        <table id="XxPay_Mgr_PayOrder_dataAll" lay-filter="XxPay_Mgr_PayOrder_dataAll"></table>
      </div>
    </div>
  </div>
</div>

<script type="text/html" id="payOrderBar">
  <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="detail">查看</a>
  {{#  if(d.status == 1){ }}
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="reissue">补单</a>
  {{#  } else { }}
  <a class="layui-btn layui-btn-danger layui-btn-xs layui-btn-disabled" lay-event="reissue">补单</a>
  {{#  } }}
</script>

<script>
layui.use(['admin', 'table', 'util', 'laydate'], function(){
  var $ = layui.$
  ,admin = layui.admin
  ,table = layui.table
  ,element = layui.element
  ,laydate = layui.laydate
  ,form = layui.form;
  
  element.render('breadcrumb', 'breadcrumb');

  $.setCountResult = function(mchId, productId, payOrderId, mchOrderNo, productType, createTimeStart, createTimeEnd) {
    admin.req({
      type: 'get',
      url: layui.setter.baseUrl + '/pay_order/count',
      data: {
        mchId : mchId,
        productId : productId,
        payOrderId : payOrderId,
        mchOrderNo : mchOrderNo,
        productType : productType,
        createTimeStart : createTimeStart,
        createTimeEnd : createTimeEnd
      },
      error: function(err){
        layer.alert(JSON.stringify(err.field), {
          title: '错误提示'
        })
      },
      success: function(res){
        if(res.code == 0){
          $('#orderPayAmountTip_allTotalCount').html(res.data.allTotalCount);
          $('#orderPayAmountTip_allTotalAmount').html("￥" + res.data.allTotalAmount/100.00);
          $('#orderPayAmountTip_successTotalCount').html(res.data.successTotalCount);
          $('#orderPayAmountTip_successTotalAmount').html("￥" + res.data.successTotalAmount/100.00);
          $('#orderPayAmountTip_successTotalMchIncome').html("￥" + res.data.successTotalMchIncome/100.00);
          $('#orderPayAmountTip_successTotalAgentProfit').html("￥" + res.data.successTotalAgentProfit/100.00);
          $('#orderPayAmountTip_successTotalPlatProfit').html("￥" + res.data.successTotalPlatProfit/100.00);
          $('#orderPayAmountTip_failTotalCount').html(res.data.failTotalCount);
          $('#orderPayAmountTip_failTotalAmount').html("￥" + res.data.failTotalAmount/100.00);
        }
      }
    });
  };

  // 加载支付产品
  admin.req({
    type: 'post',
    url: layui.setter.baseUrl + '/config/common/pay_product_all',
    error: function(err){
      layer.alert(err);
    },
    success: function(res){
      if(res.code == 0){
        var payProductList = res.data;
        //遍历赋值
        for(var i in payProductList){
          $("#productId").append('<option value= '+payProductList[i].id+'>'+payProductList[i].productName+'</option>');
        }
        form.render('select');
      }
    }
  });

  var tplStatus = function(d){
    if(d.status == 0) {
      return "<span style='color: blue'>订单生成</span>";
    }else if(d.status == 1) {
      return "<span style='color: orangered'>支付中</span>";
    }else if(d.status == 2) {
      return "<span style='color: green'>支付成功</span>";
    }else if(d.status == -1) {
      return "<span style='color: red'>支付失败</span>";
    }else if(d.status == 3) {
      return "<span style='color: darkgreen'>处理完成</span>";
    }else if(d.status == 4) {
      return "<span style='color: red'>已退款</span>";
    }
  };

  // 初始化统计结果
  $.setCountResult();

  //用户列表
  table.render({
    elem: '#XxPay_Mgr_PayOrder_dataAll'
    ,url: layui.setter.baseUrl + '/pay_order/list' //用户列表接口
    ,where: {
        access_token: layui.data(layui.setter.tableName).access_token
    }
    ,id: 'tableReload'
    ,page: true
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field: 'mchId', title: '商户ID'}
      ,{field: 'mchOrderNo', title: '商户单号'}
      ,{field: 'payOrderId', title: '支付单号'}
      ,{field: 'amount', title: '支付金额', templet: '<div>{{ d.amount/100 }}</div>'}
      ,{field: 'productType', title: '产品类型', templet: '<div>{{ d.productType == 1 ? "收款" : d.productType == 2 ? "充值" : ""}}</div>'}
      ,{field: 'status', title: '状态', templet: tplStatus}
      ,{field: 'createTime', title: '创建时间', templet: '<div>{{ layui.util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss") }}</div>'}
      ,{field: 'paySuccTime', title: '成功时间', templet: '<div>{{ layui.util.toDateString(d.createTime, "yyyy-MM-dd HH:mm:ss") }}</div>'}
      ,{field: 'edit', title: '操作', toolbar: '#payOrderBar' }
    ]]
    ,skin: 'line'
  });

  //监听工具条
  table.on('tool(XxPay_Mgr_PayOrder_dataAll)', function(obj){
    var data = obj.data;
    if(obj.event === 'detail'){
      location.href = layui.setter.baseLocal + "order/pay/view.html?" + data.payOrderId;
    }else if(obj.event === 'reissue') {
      var payOrderId = data.payOrderId;
      layer.prompt({
        formType: 1,
        title: '确认补单，请输入超级密码：'
      }, function(value, index, elem){
        layer.close(index);
        var load = layer.msg('重新发送中...', {
          icon: 16
          ,shade: 0.01
          ,time: 9999999999
        });
        admin.req({
          type: 'post',
          url: layui.setter.baseUrl + '/pay_order/reissue',
          timeout: 1000 * 60,
          data:{
            payOrderId: payOrderId,
            password: value
          },
          error: function(err){
            layer.close(load);
            layer.alert(err);
          },
          success: function(res){
            layer.close(load);
            if(res.code == 0){
              layer.alert("补单完成，请注意查看状态！");
              table.reload("tableReload");
            }
          }
        });
      });
    }
  });

  // 搜索
  var $ = layui.$, active = {
    reload: function(){
      var mchId = $('#mchId').val();
      var productId = $('#productId').val();
      var payOrderId = $('#payOrderId').val();
      var mchOrderNo = $("#mchOrderNo").val();
      var productType = $("#productType").val();
      var createTimeStart = $('#createTimeStart').val();
      var createTimeEnd = $('#createTimeEnd').val();
      var status = $("#status").val();

      $.setCountResult(mchId, productId, payOrderId, mchOrderNo, productType, createTimeStart, createTimeEnd);
      //执行重载
      table.reload('tableReload', {
        page: {
          curr: 1 //重新从第 1 页开始
        }
        ,where: {
          mchId: mchId,
          productId: productId,
          payOrderId: payOrderId,
          mchOrderNo: mchOrderNo,
          productType: productType,
          status : status,
          createTimeStart : createTimeStart,
          createTimeEnd : createTimeEnd
        }
      });
    }
  };
  $('#search').on('click', function() {
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });

  laydate.render({
    elem: '#createTimeStart'
    ,type: 'datetime'
    ,format: 'yyyy-MM-dd HH:mm:ss'
  });

  laydate.render({
    elem: '#createTimeEnd'
    ,type: 'datetime'
    ,format: 'yyyy-MM-dd HH:mm:ss'
  });
  // 渲染表单
  form.render();
});
</script>